using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Zune.Forms
{
    internal class SysControl
    {
        internal Vector2 _location = new Vector2(0, 0);
        internal Vector2 _size = new Vector2(10, 10);
        internal bool _visible = true;
        internal Color _backColor = Color.TransparentBlack;
        internal Color _foreColor = Color.Black;
        internal Control _parent;
        internal Viewport _savedViewPort;

        internal SysControl(Control parent)
        {
            _parent = parent;
        }

        internal virtual void LoadContent()
        {
        }

        internal void PreDraw()
        {
            Viewport vp = new Viewport();
            vp.X = (Int32)_location.X;
            vp.Y = (Int32)_location.Y;
            vp.Width = (Int32)_size.X;
            vp.Height = (Int32)_size.Y;
            _savedViewPort = GraphicsDevice.Viewport;
            GraphicsDevice.Viewport = vp;
        }

        internal virtual void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(BackColor);
        }

        internal void PostDraw()
        {
            GraphicsDevice.Viewport = _savedViewPort;
        }

        internal virtual void Update(GameTime gameTime, TouchCollection touches)
        {
        }

        internal Control Form
        {
            get { return _parent; }
        }

        internal SpriteBatch SpriteBatch
        {
            get
            {
                if (_parent != null)
                    return _parent._form.SpriteBatch;
                else
                    return null;
            }
        }

        internal GraphicsDevice GraphicsDevice
        {
            get
            {
                if (_parent._form != null)
                    return _parent._form.GraphicsDevice;
                else
                    return null;
            }
        }

        internal Vector2 Location
        {
            get { return _location; }
            set { _location = value; }
        }

        internal Vector2 Size
        {
            get { return _size; }
            set { _size = value; }
        }

        internal Color BackColor
        {
            get { return _backColor; }
            set { _backColor = value; }
        }

        internal Color ForeColor
        {
            get { return _foreColor; }
            set { _foreColor = value; }
        }

        internal bool Visible
        {
            get { return _visible; }
            set { _visible = value; }
        }
    }
}